

function getDCName() {
    var sel = document.getElementById("dcNameAll"); //页面发货仓下拉框数据
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/abaseservice/area/getAllWarehouse',
        cache: false, //禁用缓存
        type: "POST",
        dataType:"json",
        data:{},
        success: function(obj){
            for(var i=0;i<obj.data.length;i++){
                $(sel).append('<span class="mr-40"><input name="radioname" class="mr-5 radio change_address" type="radio" value="'+obj.data[i].warehouse_code+'" data-val="'+obj.data[i].warehouse_name+'">'+obj.data[i].warehouse_name+'</span>');
            }
            $("input[type='radio'][name='radioname']").get(0).checked = true;
            getDCdateByCode();
            list()
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}


function list(){
    $("[name='radioname']").change(function () {
        getDCdateByCode();
    })
}

function getDCdateByCode() {
    var DCcode = $("input:radio[name='radioname']:checked").val();
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/alogistics/findDispatchScopeByPage.jhtml',
        cache: false, //禁用缓存
        type: "POST",
        data: {
            pageSize: 20,
            pageNum: 1,
            warehouseCode:DCcode
        },
        success: function(data){
            if(data.errorCode=="0"){
                allData = data;
                goodsList(allData);
            }else {
                layer.msg(data.errorMessage, {icon: 1,time:1000});
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}

function goodsList(dataList) {
    //console.log(allData)
    if(dataSource.length>0){
        dataSource.splice(0, dataSource.length); //清空数组
    }
    if(dataList.data.result!=null){
        $.each(dataList.data.result, function(i, field) {
            var rowData = new Array();
            rowData.push(field.transportModeType);
            rowData.push(field.areaName);
            rowData.push(field.status);
            rowData.push(field.createUser);
            rowData.push(field.createTime);
            dataSource.push(rowData);
            rowData.push(field.id);
            rowData.push(field.areaCode);
        });
    }
    rangeDataTable(dataSource);
    function rangeDataTable(dataSource) {
        var dttable = $('#agingTable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#agingTable").DataTable({
            "autoWidth": false,
            "ordering": true,
            "searching": true,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": [50, 25, 10, 5],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />"
            },
            data: dataSource,
            columnDefs: [{
                "visible": true,
                "targets": 0
            }/*,

                {
                    "render": function(data, type, row, meta) {
                        if(row[0] == 40){
                            return '鑫方盛物流';
                        }else if (row[0] == 10) {
                            return '快递';
                        }else if (row[0] == 20) {
                            return '快运';
                        }else if (row[0] == 30) {
                            return '专车包车';
                        }
                    },
                    "targets": 0
                },


                {
                    "render": function(data, type, row, meta) { // 1,6
                        var idList =row[6].split(",");
                        var nameList = row[1].split(",");
                        var ulTop = '<ul class="radius text-l" id="ulList">';
                        var list="";
                        var ulfoot ='</ul><a class="edit" style="float: right;" onclick="area(\'修改覆盖范围\',this,'+row[5]+','+row[0]+')">编辑</a>';
                        for(var i=0;i<idList.length;i++){
                            list += '<li class="f-l ml-10 liList" id="'+idList[i]+'"><span class="name">'+nameList[i]+'</span><sup style="color:#ff1b1b; cursor:pointer;">' +
                                '<b onclick="remove(this,'+row[5]+','+row[0]+')">x</b></sup></li>'
                        }

                        ulTop += list + ulfoot;
                        return ulTop;
                    },
                    "targets": 1
                },

                {
                    "render": function(data, type, row, meta) {
                        if(row[2] == 10){
                            return '有效';
                        }else{
                            return '无效';
                        }
                    },
                    "targets": 2
                },

                {
                    "render": function(data, type, row, meta) {
                        var val = '<a onclick="relation_update(\'修改覆盖范围\','+row[0]+')"><span id="areaList" class="list">修改</span></a>';
                        return val;
                    },
                    "targets": 5
                },*/
            ]
        });
    };
}
